<?php

function list_performance($periode_id){
	$header = array(
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Nama Karyawan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'No. Posisi'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'Gol'=>array('style'=>'border-bottom:2px solid;width:5%'),
		'Nilai'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Keterangan'=>array('style'=>'border-bottom:2px solid;width:15%'),  
	);
	
	$query = "SELECT a.karyawan_id,e.nomor_posisi,e.nama_jabatan,h.kode_golongan_jabatan,g.huruf, g.keterangan FROM penilaian_karyawan a
		INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id
		INNER JOIN karyawan c ON c.karyawan_id = a.karyawan_id
		INNER JOIN biodata d ON d.biodata_id = c.biodata_id
		INNER JOIN jabatan e ON e.jabatan_id = b.jabatan_id
		INNER JOIN penilaian f ON f.penilaian_id = a.penilaian_id
		INNER JOIN evaluasi_nilai g ON g.evaluasi_nilai_id = a.evaluasi_nilai_id
		INNER JOIN golongan_jabatan h ON h.golongan_jabatan_id = e.golongan_jabatan_id
		WHERE 1";
		
	if( $periode_id>0 ){
		$query .= " AND a.penilaian_id={$periode_id}";
	}			
	if(isset($_GET['knik']) AND $_GET['knik']<>''){
		$query .= " AND c.nik={$_GET['knik']}";
	}
	if(isset($_GET['kpos']) AND $_GET['kpos']<>''){
		$query .= " AND e.nomor_posisi={$_GET['kpos']}";
	}
	if(isset($_GET['kgol']) AND $_GET['kgol']<>0){
		$query .= " AND h.golongan_jabatan_id={$_GET['kgol']}";
	}
	if(isset($_GET['knilai']) AND $_GET['knilai']<>0){
		$query .= " AND g.huruf='{$_GET['knilai']}'";
	}
	$query .= " ORDER BY c.NIK";	
	$result = my_query($query);
	$total_records = my_num_rows($result );
	$scroll_page =5;  
	$per_page =15;  
	$current_page = isset($_GET['page']) ? (int) $_GET['page'] : 1 ; 
	if($current_page < 1){
		$current_page = 1;
	}		 
	$pager_url  ="index.php?com={$_GET['com']}&task={$_GET['task']}
		&periode_id={$periode_id}&knik={$_GET['knik']}&kpos={$_GET['kpos']}&kgol={$_GET['kgol']}&knilai={$_GET['knilai']}&page=";	 
	$inactive_page_tag = 'style="padding:4px;background-color:#BBBBBB"';  
	$previous_page_text = ' Mundur '; 
	$next_page_text = ' Maju ';  
	$first_page_text = ' Awal '; 
	$last_page_text = ' Akhir ';
	
	$kgPagerOBJ = new kgPager();
	$kgPagerOBJ->pager_set(
		$pager_url, 
		$total_records, 
		$scroll_page, 
		$per_page, 
		$current_page, 
		$inactive_page_tag, 
		$previous_page_text, 
		$next_page_text, 
		$first_page_text, 
		$last_page_text ,$pager_url_last); 
	 		
	$result = my_query($query ." LIMIT ".$kgPagerOBJ->start.", ".$kgPagerOBJ->per_page); 		
	$row = array();
	while($ey = my_fetch_array($result) ){
		$karyawan = loaddata_karyawan($ey['karyawan_id']); 
		$row[] = array(
			'nik'=>  $karyawan['nik'] ,
			'nama'=>  $karyawan['nama_gelar'] , 
			'nopos'=> $ey['nomor_posisi'] ,   
			'jabat'=> $ey['nama_jabatan'] ,   
			'gol'=> position_text_align( $ey['kode_golongan_jabatan'], 'center'),
			'huruf'=> position_text_align( $ey['huruf'], 'center'),
			'keterangan'=> $ey['keterangan'] ,   
		);		
	}	
	$datas = table_rows($row);
	$paging = $kgPagerOBJ ->showPaging();
	$menuontop = array(  
		'Cetak' => array('onclick'=>'javascript:window.open(\'index.php?com='.$_GET['com'].'&task=plaincetak&&periode_id='.$periode_id.'&knik='.$_GET['knik'].'&kpos='.$_GET['kpos'].'&kgol='.$_GET['kgol'].'&knilai='.$_GET['knilai'].'\',\'mywin\',\'left=20,top=20,width=800,height=600,toolbar=0,scrollbars,resizable=0\');'),
		'Excel'=>array('onclick'=>'javascript:location.href=\'index.php?com='.$_GET['com'].'&task=excel&&periode_id='.$periode_id.'&knik='.$_GET['knik'].'&kpos='.$_GET['kpos'].'&kgol='.$_GET['kgol'].'&knilai='.$_GET['knilai'].'\';'),
	);

	$aperiode = array();
	$query = "SELECT * FROM penilaian ORDER BY tanggal  DESC";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$aperiode[$row['penilaian_id']] = date('m-Y',strtotime($row['tanggal']));
	 }
	$form_periode = array(
		'name'=>'periode_id',
		'id'=>'periode_id',
		'value'=>$periode_id
	);

	$agol = array();
	$query = "SELECT * FROM golongan_jabatan ORDER BY golongan_jabatan_id  DESC";
	$re = my_query($query);
	while($row = my_fetch_array($re) ){
		$agol[$row['golongan_jabatan_id']] = $row['kode_golongan_jabatan'];
	 }
	$form_gol = array(
		'name'=>'kgol',
		'id'=>'kgol',
		'value'=>isset($_GET['kgol']) ? $_GET['kgol'] : 0 
	);
	
	$temp=array();
	$temp['A']="A" ;
	$temp['B']="B" ;
	$temp['C']="C" ;
	$temp['D']="D" ;
	$temp['E']="E" ;
	$form_nilai = array(
		'name'=>'knilai',
		'id'=>'knilai',
		'value'=>isset($_GET['knilai']) ? $_GET['knilai'] : ' ' 
	);		
	$search = '<form method="GET">
	<input type="hidden" name="com" value="'.$_GET['com'].'" />
	<span style="font:10px verdana"><b>Periode </b></span>'.form_dropdown($form_periode , $aperiode).'
	<span style="font:10px verdana"><b>NIK </b></span>
	<input type="text"  style="width:70px;" name="knik" value="'.(isset($_GET['knik']) ? $_GET['knik']: "").'" />
	<span style="font:10px verdana"><b>No. Posisi </b></span>
	<input type="text"  style="width:70px;" name="kpos" value="'.(isset($_GET['kpos']) ? $_GET['kpos']: "").'" />
	<span style="font:10px verdana"><b>Gol. </b></span>'.form_dropdown($form_gol , $agol).'
	<span style="font:10px verdana"><b>Nilai </b></span>'.form_dropdown($form_nilai , $temp).'
	<input class="button" type="submit" value=" Cari " /> </form>';	
	$printmenu = additional_menu_on_list( $menuontop ,'');
	return $search.$printmenu.table_builder($header , $datas ,  15 , false  , $paging  );
}


function excel_report($periode_id){
	my_component_load('xl_builder' , false);

	$header = array(
		'NIK'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Nama Karyawan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'No. Posisi'=>array('style'=>'border-bottom:2px solid;width:10%'),  
		'Jabatan'=>array('style'=>'border-bottom:2px solid;width:25%'),  
		'Gol'=>array('style'=>'border-bottom:2px solid;width:5%'),
		'Nilai'=>array('style'=>'text-align:center;border-bottom:2px solid;width:10%'),  
		'Keterangan'=>array('style'=>'border-bottom:2px solid;width:15%'),  
	);
	
	$query = "SELECT a.karyawan_id,e.nomor_posisi,e.nama_jabatan,h.kode_golongan_jabatan,g.huruf, g.keterangan FROM penilaian_karyawan a
		INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id
		INNER JOIN karyawan c ON c.karyawan_id = a.karyawan_id
		INNER JOIN biodata d ON d.biodata_id = c.biodata_id
		INNER JOIN jabatan e ON e.jabatan_id = b.jabatan_id
		INNER JOIN penilaian f ON f.penilaian_id = a.penilaian_id
		INNER JOIN evaluasi_nilai g ON g.evaluasi_nilai_id = a.evaluasi_nilai_id
		INNER JOIN golongan_jabatan h ON h.golongan_jabatan_id = e.golongan_jabatan_id
		WHERE 1";
		
	if( $periode_id>0 ){
		$query .= " AND a.penilaian_id={$periode_id}";
	}			
	if(isset($_GET['knik']) AND $_GET['knik']<>''){
		$query .= " AND c.nik={$_GET['knik']}";
	}
	if(isset($_GET['kpos']) AND $_GET['kpos']<>''){
		$query .= " AND e.nomor_posisi={$_GET['kpos']}";
	}
	if(isset($_GET['kgol']) AND $_GET['kgol']<>0){
		$query .= " AND h.golongan_jabatan_id={$_GET['kgol']}";
	}
	if(isset($_GET['knilai']) AND $_GET['knilai']<>0){
		$query .= " AND g.huruf='{$_GET['knilai']}'";
	}
	$query .= " ORDER BY c.NIK";
	$result = my_query($query );
	$row = array(); 
	while($ey = my_fetch_array($result )){
		$karyawan = loaddata_karyawan($ey['karyawan_id']); 
		$jabatan = loaddata_jabatan($karyawan['jabatan_id']); 
		$row[] = array(
			'nik'=>  $karyawan['nik'] ,
			'nama'=>  $karyawan['nama_gelar'] , 
			'nopos'=> $ey['nomor_posisi'] ,   
			'jabat'=> $ey['nama_jabatan'] ,   
			'gol'=> position_text_align( $ey['kode_golongan_jabatan'], 'center'),
			'huruf'=> position_text_align( $ey['huruf'], 'center'),
			'keterangan'=> $ey['keterangan'] ,   
		);			
	}
	
	$datas = table_rows_excel($row); 
	return table_builder_excel($header , $datas , 15 ,false ); 
}

function print_plain($periode_id){
	$periodes = my_get_data_by_id('pr_periode','periode_id',$periode_id);

	$datas = array();  
	$datas[] = array(
		 'k1'=>array("NIK" ,10,STR_PAD_RIGHT),
		 'k2'=>array("Nama Karyawan" ,25,STR_PAD_RIGHT),
		 'k3'=>array("No. Posisi" ,10 ,STR_PAD_RIGHT),
		 'k4'=>array("Jabatan" ,25,STR_PAD_RIGHT),  
		 'k5'=>array("Gol." ,5,STR_PAD_BOTH),  
		 'k6'=>array("Nilai" ,10,STR_PAD_BOTH),  
		 'k7'=>array("Keterangan" ,15,STR_PAD_RIGHT),  
	); 	
	$datas[] = array(
		 'k1'=>array(" " ,100 ,STR_PAD_BOTH),	
	); 	
	
	$query = "SELECT a.karyawan_id,e.nomor_posisi,e.nama_jabatan,h.kode_golongan_jabatan,g.huruf, g.keterangan FROM penilaian_karyawan a
		INNER JOIN kekaryawanan b ON b.karyawan_id = a.karyawan_id
		INNER JOIN karyawan c ON c.karyawan_id = a.karyawan_id
		INNER JOIN biodata d ON d.biodata_id = c.biodata_id
		INNER JOIN jabatan e ON e.jabatan_id = b.jabatan_id
		INNER JOIN penilaian f ON f.penilaian_id = a.penilaian_id
		INNER JOIN evaluasi_nilai g ON g.evaluasi_nilai_id = a.evaluasi_nilai_id
		INNER JOIN golongan_jabatan h ON h.golongan_jabatan_id = e.golongan_jabatan_id
		WHERE 1";
		
	if( $periode_id>0 ){
		$query .= " AND a.penilaian_id={$periode_id}";
	}			
	if(isset($_GET['knik']) AND $_GET['knik']<>''){
		$query .= " AND c.nik={$_GET['knik']}";
	}
	if(isset($_GET['kpos']) AND $_GET['kpos']<>''){
		$query .= " AND e.nomor_posisi={$_GET['kpos']}";
	}
	if(isset($_GET['kgol']) AND $_GET['kgol']<>0){
		$query .= " AND h.golongan_jabatan_id={$_GET['kgol']}";
	}
	if(isset($_GET['knilai']) AND $_GET['knilai']<>0){
		$query .= " AND g.huruf='{$_GET['knilai']}'";
	}
	$query .= " ORDER BY c.NIK";
	$result = my_query($query ); 
	while($ey = my_fetch_array($result)){
		$karyawan = loaddata_karyawan($ey['karyawan_id']); 
		$datas[] = array(
			 'k1'=>array($karyawan['nik'] ,10,STR_PAD_RIGHT),
			 'k2'=>array($karyawan['nama_gelar'] ,25,STR_PAD_RIGHT),
			 'k3'=>array($ey['nomor_posisi'] ,10 ,STR_PAD_RIGHT),
			 'k4'=>array($ey['nama_jabatan'] ,25,STR_PAD_RIGHT),  
			 'k5'=>array($ey['kode_golongan_jabatan'] ,5,STR_PAD_BOTH),  
			 'k6'=>array($ey['huruf'] ,10,STR_PAD_BOTH),  
			 'k7'=>array($ey['keterangan'] ,15,STR_PAD_RIGHT),  
		); 			
	}
	$view = 	str_pad("PERFORMANCE REPORT",100," ",STR_PAD_BOTH);
	return $view ."\n"."\n".set_txt_report($datas);
}
